const crypto = require('crypto');
// 生成一个随机的 256 位密钥
const key = crypto.randomBytes(32);

// 生成一个随机的 16 位 IV（初始化向量）
const iv = crypto.randomBytes(16);

// 加密函数
function encrypt(text) {
    const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
    let encrypted = cipher.update(text, 'utf8', 'hex');
    encrypted += cipher.final('hex');
    return encrypted;
}

// 解密函数
function decrypt(text) {
    const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
    let decrypted = decipher.update(text, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;
}
module.exports = {
    encrypt,decrypt
}